From f4e91546a44a393000dea8607920a5cee52a1594 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 23 Sep 2014 22:23:10 -0700 Subject: [PATCH] Make a test more resilient against the host system If the host system had $HOME/.cargo/config which configured a user name/email then this test would fail because those would be prioritized over $USER. Closes #514 --- tests/test_cargo_new.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_cargo_new.rs b/tests/test_cargo_new.rs index 61b693602..bd25aab41 100644 --- a/tests/test_cargo_new.rs +++ b/tests/test_cargo_new.rs @@ -1,4 +1,4 @@ -use std::io::{fs, UserRWX, File}; +use std::io::{fs, UserRWX, File, TempDir}; use std::io::fs::PathExtensions; use std::os; @@ -101,10 +101,14 @@ test!(existing { }) test!(finds_author_user { - assert_that(cargo_process("new").arg("foo").env("USER", Some("foo")), + // Use a temp dir to make sure we don't pick up .cargo/config somewhere in + // the hierarchy + let td = TempDir::new("cargo").unwrap(); + assert_that(cargo_process("new").arg("foo").env("USER", Some("foo")) + .cwd(td.path().clone()), execs().with_status(0)); - let toml = paths::root().join("foo/Cargo.toml"); + let toml = td.path().join("foo/Cargo.toml"); let toml = File::open(&toml).read_to_string().assert(); assert!(toml.as_slice().contains(r#"authors = ["foo"]"#)); }) -- 2.30.2